#include <iostream>
#include <cstring>
#include <queue>
#include <string>
using namespace std;
struct Node{
    int x,y,num,step;
	string s;
	Node(int xx,int yy,int nnum,int sstep,string ss):x(xx),y(yy),num(nnum),step(sstep),s(ss){
	}
};
bool isUsedd[400000];
int map[3][3];
bool isUsed[10];
int nn[10];
int jiecheng(int n){
	int item=1;
	for(int i=n;i>=1;i--){
		item*=i;
	}
	return item;
}
int zhuan(int n){
	for(int i=8;i>=0;i--){
		nn[i]=n%10;
		n=n/10;
		//cout<<nn[i]<<" ";
	}
	//cout<<endl;
	int sum=0;
	for(int i=0;i<9;i++){
		for(int j=0;j<nn[i];j++){
			if(!isUsed[j]){
				sum+=jiecheng(8-i);
			}
		}
		isUsed[nn[i]]=true;
	}
	memset(isUsed,false,sizeof(isUsed));
	return sum;
}//132748
queue<Node> q;
int zhuanitem(int n){
	int item=1;
	for(int i=n;i<8;i++){
		item*=10;
	}
	return item;
} 
int qu(int n,int pre){
	//123456780
	int nn;
	int t=9-pre;
	while(t!=0){
		nn=n%10;
		n=n/10;
		t--;
	}
	return nn;
}
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main(){
	int sum=0;
	int num=123456780;
	//int num=1234567890;
	memset(isUsed,false,sizeof(isUsed));
	int znum=zhuan(num);
	memset(isUsed,false,sizeof(isUsed));
	//cout<<zhuan(234150768)<<endl;
	//cout<<zhuan(234105768)<<endl;
	int tempx,tempy;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>map[i][j];
			if(map[i][j]==0){
				tempx=i;
				tempy=j;
			}
			sum+=map[i][j]*zhuanitem((i*3+j));
		}	
	}

	memset(isUsedd,false,sizeof(isUsedd));
	//cout<<sum<<endl;
	//cout<<zhuan(sum)<<endl;
	q.push(Node(tempx,tempy,sum,0,""));
	isUsedd[zhuan(sum)]=true;
	//cout<<"111"<<endl;
	int ppp=0;
	while(!q.empty()){
		//ppp++;
		//if(ppp>10){
		//	break;
	//	} 
		Node nnn=q.front();
		if(znum==zhuan(nnn.num)){
			//cout<<num<<" "<<nnn.num<<endl;
			cout<<nnn.step<<endl;
			cout<<nnn.s<<endl;
			//return 0;
		}
		//cout<<nnn.x<<" "<<nnn.y<<" "<<nnn.num<<endl;
		for(int i=0;i<4;i++){
			int tx=nnn.x+dx[i];
			int ty=nnn.y+dy[i];
			//cout<<tx<<" "<<ty<<endl;
			if(tx>=0&&tx<3&&ty>=0&&ty<3){
				int ttp=tx*3+ty;
				int p=nnn.x*3+nnn.y;
				//1 2 3 4 5 6
				//1 3 2 4 5 6
				//cout<<qu(nnn.num,ttp)<<" "<<qu(nnn.num,p)<<endl; 
				int ttsum=nnn.num+(qu(nnn.num,ttp)-qu(nnn.num,p))*zhuanitem(p)+(qu(nnn.num,p)-qu(nnn.num,ttp))*zhuanitem(ttp);
				//cout<<tx<<" "<<ty<<" "<<ttp<<" "<<p<<" "<<ttsum<<endl;
				//memset(isUsed,false,sizeof(isUsed));
				//            x y
				//234105768   5 4
				//cout<<tx<<" "<<ty<<" "<<ttp<<" "<<p<<" "<<ttsum<<" "<<zhuan(ttsum)<<" "<<znum<<endl;
				/*if(znum==zhuan(ttsum)){
					cout<<nnn.step+1<<endl;
					cout<<nnn.s<<endl;
					return 0;
				}*/
				//memset(isUsed,false,sizeof(isUsed));
				if(!isUsedd[zhuan(ttsum)]){
					isUsedd[zhuan(ttsum)]=true;
					//cout<<tx<<" ddf "<<ty<<" "<<ttsum<<endl;
					if(i==0){
						q.push(Node(tx,ty,ttsum,nnn.step+1,nnn.s+"r"));
						
					}
					else if(i==1){
						q.push(Node(tx,ty,ttsum,nnn.step+1,nnn.s+"l"));
					
					}
					else if(i==2){
						q.push(Node(tx,ty,ttsum,nnn.step+1,nnn.s+"d"));
						
					}
					else{
						q.push(Node(tx,ty,ttsum,nnn.step+1,nnn.s+"u"));
						
					}
				}
			}
		}
		q.pop();
	}
	return 0;
}
/*1 2 3
4 5 6
7 8 0*/
